<?php

namespace App\Http\Requests;

use App\Article;
use Illuminate\Foundation\Http\FormRequest;
use Service\ArticleService;

class ArticlePost extends FormRequest
{
    public $title;
    public $category_id;
    public $body;
    public $user_id;
    public $create_at;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'title' => 'required|max:100',
            'category_id' => 'required',
            'body' => 'required',
        ];
    }

    public function storeNewArticle(){
        $model = new Article();
        //没看见create方法，5.4不支持？或者是我的IDE原因
        foreach($this as $k=>$v){
            $model->$k = $v;
        }
        ArticleService::publishArticle($model);
    }
}
